﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using ZLCMS.Business;
using System.Text;
using NHibernate.Criterion;
using ZLCMS.Data.Common;
using NHibernate;
using ZLCMS.Data.Model;
using ZLCMS.Business.Config;
using ZLCMS.Business.ShopCart;
using ZLCMS.Business.Util;
using System.Collections.Generic;
using Newtonsoft.Json;
using ZLCMS.Business.Common;
using DotNet.Common.NHibernateUtil;

namespace ZLCMS.Web.ShopCart
{
    public partial class ShoppingCart : System.Web.UI.Page
    {
        protected decimal _totalPrice = 0; //合计
        protected decimal _totalWeight = 0;//商品重量
        protected int _totalCount = 0; //商品数量

        protected void Page_Load(object sender, EventArgs e)
        {
            List<ShopCartCookiesInfo> ProductList = new ShoppingCartKit().ProductList;

            rp_productlist.DataSource = ProductList;
            rp_productlist.DataBind();
        }

        protected void rp_productlist_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                ShopCartCookiesInfo productCartItem = (ShopCartCookiesInfo)e.Item.DataItem;
                using (ISession session = SessionFactoryHelper.CreateSession())
                {
                    ShopProductInfo product = session.Get<ShopProductInfo>(productCartItem.ProductId);
                    if (product != null)
                    {
                        (e.Item.FindControl("img_product") as Image).ImageUrl = FileKit.FirstFilePath(product.ThumbnailImg);
                        (e.Item.FindControl("lb_productname") as Label).Text = product.ProductName;
                        (e.Item.FindControl("lb_price") as Label).Text = product.SalePrice.ToString("0.00");
                        (e.Item.FindControl("lb_totalprice") as Label).Text = (product.SalePrice * productCartItem.Quantity).ToString("0.00");

                        _totalPrice += product.SalePrice * productCartItem.Quantity;
                        _totalWeight += product.Weight * productCartItem.Quantity;
                        _totalCount += productCartItem.Quantity;
                    }
                }
              
            }
        }
    }
}
